# -*- coding: utf-8 -*-
from google.appengine.ext import db
#from google.appengine.api import memcache
from google.appengine.api import users
#from conference.conferenceapp import my
#from google.appengine.ext.db import NotSavedError
#from google.appengine.api.users import User

class Users (db.Model):
	googleProperties = db.UserProperty(auto_current_user=True)
	dateIn = db.DateTimeProperty(auto_now_add=1)
	def __str__(self):
		return '%s' % str(self.googleProperties)
	
	def __url__(self):
		return '%s' % str(self.googleProperties.name)
	
class Receipts(db.Model):
	afm = db.IntegerProperty()
	amount = db.FloatProperty()
	storeDescription = db.StringProperty()
	date = db.DateProperty()
	creator = db.ReferenceProperty(Users)
	def __str__(self):
		return '%s, %s' % (self.amount, self.storeDescription)

	def put(self):
		sesUser = users.get_current_user()
		if not sesUser:
			print "user not logged in"
#			raise exception
		userObject = Users.all().filter("googleProperties = ", sesUser).get()
		if self.creator is None:
			self.creator = userObject
		super(Receipts, self).put()